<?php

namespace app\controller\admin\v1\recovery;

use app\controller\admin\AuthController;
use app\model\v1\gift\GiftCardCate;
use app\model\v1\recovery\ConfigActivity;
use app\model\v1\recovery\ConfigBanner;
use app\model\v1\recovery\ConfigServ;
use app\model\v1\recovery\RecoveryFeedBack;
use app\model\v1\recovery\RecoveryFeedBackItem;
use app\model\v1\recovery\RecoveryInstruction;
use app\model\v1\recovery\RecoveryShop;
use app\model\v1\recovery\SystemOperationLog;
use app\model\v1\recovery\RecoveryProductCategory;
use app\model\v1\recovery\RecoveryProductShop;
use app\model\v1\recovery\RecoveryQuestion;
use app\model\v1\recovery\RecoveryQuestionCate;
use app\model\v1\recovery\RecoveryQuestionType;
use app\model\v1\recovery\RecoveryRegAuth;
use app\model\v1\recovery\RecoveryReport;
use app\model\v1\recruit\RecruitJobCate;
use app\services\product\category\StoreProductCategoryServices;
use app\services\product\product\StoreProductServices;
use app\validate\api\recovery\productValidate;
use think\facade\App;
use app\Request;
use app\model\v1\recovery\RecoveryProduct as productModel;


class RecoveryProduct extends AuthController
{
    protected $model;

    public function __construct(App $app, productModel $model)
    {
        parent::__construct($app);
        $this->model = $model;
    }


    /**
     * banner管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getConfigBannerList (Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        $data = ConfigBanner::getBannerList($param);

        return $this->success($data);
    }


    /**
     * banner管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function deleteBanner(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = ConfigBanner::where("id", $param['id'])->update(['delete_time'=>date("Y-m-d H:i:s")]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'recovery','banner管理列表','deleteBanner','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }


    /**
     * banner管理列表 - 查看
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getBannerDetail(Request $request)
    {
        $param = $request->param();
        if(empty($param["id"])) return $this->fail('id不能为空');

        $detail = ConfigBanner::getBannerDetail($param);

        return $this->success($detail ? $detail->toArray() : []);
    }


    /**
     * banner管理列表 - 编辑
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function updateBanner(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['show_position'])) return $this->fail('show_position展示模块不能为空');
        if(empty($param['client_type'])) return $this->fail('client_type客户端类型不能为空');
        if(empty($param['banner_img'])) return $this->fail('banner_img图片路径不能为空');
        if(!empty($param["link_type"])){
            if(empty($param['link_content'])) return $this->fail('link_content链接url不能为空');
        }
        if(!empty($param["panner_title"])){
            ////$find = ConfigBanner::where("panner_title", $param["panner_title"])->where("status",1)->where("id", "<>",$param["id"])->find();
            ////if(!empty($find)) return $this->fail('标题重复！');
        }

        $res = ConfigBanner::updateBanner($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：标题：{$param["panner_title"]}.";
        SystemOperationLog::addSystemLog($admin_id,'recovery','banner管理列表','updateBanner','编辑',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('编辑成功');
        return $this->fail('编辑失败');
    }


    /**
     * 添加banner
     * @param Request $request
     * @return mixed
     */
    public function addRecoveryBanner(Request $request)
    {
        $param = $request->param();
        if(empty($param['show_position'])) return $this->fail('show_position展示模块不能为空');
        if(empty($param['client_type'])) return $this->fail('client_type客户端类型不能为空');
        if(empty($param['banner_img'])) return $this->fail('banner_img图片路径不能为空');
        if(!empty($param["link_type"])){   //link_type为1、2、3的情况下， link_content为必填字段
            if(empty($param['link_content'])) return $this->fail('link_content链接url不能为空');
        }

        $param["admin_id"] = $this->adminId;
        $res = ConfigBanner::createConfigLunbotu($param);
        if($res > 0){
            return $this->success('success');
        }
        return $this->fail('添加失败');
    }



    /**
     * 日志管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getSystemLogList (Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        $data = SystemOperationLog::getSystemLogList($param);

        return $this->success($data);
    }


    /**
     * 获取商品分类
     * @param Request $request
     * @return mixed
     */
    public function getProCategoryList(Request $request)
    {
        $param = $request->param();

        $data = RecoveryProductCategory::getProCategoryList($param);

        return $this->success($data);
    }


    /**
     * banner管理列表 - 获取展示位置模块列表
     * @param Request $request
     * @return mixed
     */
    public function getShowPositionList(Request $request)
    {
        $param = $request->param();

        $data = ConfigBanner::getShowPositionList($param);

        return $this->success($data);
    }

    public function getQuestionCategoryList(Request $request)
    {
        $param = $request->param();

        $data = RecoveryFeedBack::getQuestionCategoryList($param);
        return $this->success($data);
    }


    public function getCategoryPidList(Request $request)
    {
        $param = $request->param();
        $data = RecoveryProductCategory::getCategoryPidList($param);
        return $this->success($data);
    }

    /**
     * banner管理列表 - 启用禁用状态更新
     * @param Request $request
     * @return mixed
     */
    public function enableBannerStatus(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = ConfigBanner::enableBannerStatus($param);

        return $this->success($msg);
    }


    /**
     * 发布商品管理列表
     * @param Request $request
     * @return mixed
     */
    public function getProductList(Request $request)
    {
        $param = $request->post();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = productModel::getProductList($param);
        return $this->success($data);
    }


    /**
     * 商品管理列表 - 详情
     * @param Request $request
     * @return mixed
     */
    public function getProductDetail(Request $request)
    {
        $param = $request->post();
        if(empty($param["id"])) return $this->fail('id不能为空');

        $detail = productModel::getProductDetail($param);

        return $this->success($detail ? $detail->toArray() : []);
    }


    /**
     * 宝贝编辑
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function updateProduct(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $param = $request->postMore([
            ['category_id', ''],
            ['brand', ''],
            ['product_name', ''],
            ['price', ''],
            ['warranty', ''],
            ['is_invoice', ''],
            ['is_sale', ''],
            ['use_date', ''],
            ['images', ''],
            ['product_desc', ''],
            ['address', ''],
            ['detail_address', ''],
            ['type', 1],
        ]);
        validate(productValidate::class)->check($param);

        $res = productModel::updateProduct($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：宝贝名称：{$param["product_name"]}.";
        SystemOperationLog::addSystemLog($admin_id,'recovery','宝贝管理列表','updateProduct','编辑',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('success');
        }
        return $this->fail('fail');
    }


    /**
     * 宝贝审核
     * @param Request $request
     * @return mixed
     */
    public function updateProductGoods(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['status'])) return $this->fail('status不能为空');
        $msg = "通过";
        if($param["status"] == 2){
            if(empty($param['reason'])) return $this->fail('reason不通过原因不能为空');
            $msg = "不通过";
        }

        $res = productModel::updateProductGoods($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的宝贝{$msg}.";
        SystemOperationLog::addSystemLog($admin_id,'recovery','宝贝管理列表','updateProductGoods','宝贝审核',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('success');
        }
        return $this->fail('fail');
    }



    /**
     * 宝贝删除
     * @param Request $request
     * @return mixed
     */
    public function delProduct(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = productModel::where("id", $param["id"])->update(["delete_time" => time()]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的宝贝删除.";
        SystemOperationLog::addSystemLog($admin_id,'recovery','宝贝管理列表','delProduct','删除',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('success');
        }
        return $this->fail('fail');
    }


    /**
     * 店铺转让管理列表
     * @param Request $request
     * @return void
     */
    public function getProductShopList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = RecoveryProductShop::getProductShopList($param);

        return $this->success($data);
    }


    /**
     * 店铺转让管理列表 - 详情
     * @param Request $request
     * @return void
     */
    public function getProductShopDetail(Request $request)
    {
        $param = $request->param();
        if(empty($param["id"])) return $this->fail('id不能为空');

        $detail = RecoveryProductShop::getProductShopDetail($param);

        return $this->success($detail ? $detail->toArray() : []);
    }


    /**
     * 店铺转让管理列表 - 审核
     * @param Request $request
     * @return mixed
     */
    public function enableShopStatus(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['status'])) return $this->fail('status不能为空');
        $msg = "通过";
        if($param["status"] == 3){
            $msg = "不通过";
            if(empty($param['audit_desc'])) return $this->fail('audit_desc原因描述不能为空');
        }

        $res = RecoveryProductShop::enableShopStatus($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的店铺转让审核为{$msg}.";
        SystemOperationLog::addSystemLog($admin_id,'recovery','店铺转让管理列表','enableShopStatus','审核',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('success');
        }
        return $this->fail('fail');
    }


    /**
     * 宝贝管理列表 - 启用禁用状态更新
     * @param Request $request
     * @return mixed
     */
    public function enableRecoveryProductStatus(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = productModel::enableRecoveryProductStatus($param);

        return $this->success($msg);
    }



    /**
     * 店铺转让管理列表 - 启用禁用状态更新
     * @param Request $request
     * @return mixed
     */
    public function enableProductShopStatus(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = RecoveryProductShop::enableProductShopStatus($param);

        return $this->success($msg);
    }


    /**
     * 实名管理列表
     * @param Request $request
     * @return mixed
     */
    public function getRegAuthUserList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = RecoveryRegAuth::getRegAuthUserList($param);

        return $this->success($data);
    }


    /**
     * 实名管理列表 - 审核按钮
     * @param Request $request
     * @return mixed
     */
    public function enableRegUserStatus(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['status'])) return $this->fail('status不能为空');
        $msg = "通过";
        if($param["status"] == 3){
            if(empty($param['audit_desc'])) return $this->fail('audit_desc原因描述不能为空');
            $msg = "不通过";
        }

        $res = RecoveryRegAuth::enableRegUserStatus($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的实名认证审核为{$msg}.";
        SystemOperationLog::addSystemLog($admin_id,'recovery','实名管理列表','enableRegUserStatus','审核',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('success');
        }
        return $this->fail('fail');
    }



    /**
     * 实名管理列表 - 查看
     * @param Request $request
     * @return mixed
     */
    public function getRegAuthUserDetail(Request $request)
    {
        $param = $request->param();
        if(empty($param["id"])) return $this->fail('id不能为空');

        $detail = RecoveryRegAuth::getRegAuthUserDetail($param);

        return $this->success($detail ? $detail->toArray() : []);
    }


    /**
     * 问题分类管理列表
     * @param Request $request
     * @return void
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getFeedbackCateList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = RecoveryFeedBack::getFeedbackCateList($param);
        return $this->success($data);
    }


    /**
     * 问题分类管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function deleteFeedback(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = RecoveryFeedback::where("id", $param['id'])->update(['delete_time'=>date("Y-m-d H:i:s")]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'recovery','问题分类管理列表','deleteFeedback','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }


    /**
     * 问题分类管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function updateFeedback(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['list_item'])) return $this->fail('list_item分类名称不能为空');

        $param["admin_id"] = $this->adminId;
        $res = RecoveryFeedback::updateFeedback($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：分类名称：{$param['list_item']}.";
        SystemOperationLog::addSystemLog($admin_id,'recovery','问题分类管理列表','updateFeedback','编辑',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('编辑成功');
        }
        return $this->fail('编辑失败');
    }


    /**
     * 问题分类管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addFeedback(Request $request)
    {
        $param = $request->post();
        if(empty($param['cate_name'])) return $this->fail('cate_name分类名称不能为空');

        $param["admin_id"] = $this->adminId;
        $res = RecoveryFeedback::addFeedback($param);
        if($res > 0){
            return $this->success('success');
        }
        return $this->fail('fail');
    }


    /**
     * 问题分类管理列表 - 启用禁用
     * @param Request $request
     * @return mixed
     */
    public function enableFeedback(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = RecoveryFeedback::enableFeedback($param);

        return $this->success($msg);
    }


    /**
     * 常见问题管理列表
     * @param Request $request
     * @return mixed
     */
    public function getFeedbackItemList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = RecoveryFeedBackItem::getQuestionList($param);
        return $this->success($data);
    }


    /**
     * 常见问题管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addFeedbackItem(Request $request)
    {
        $param = $request->post();
        if(empty($param['content'])) return $this->fail('content问题标题不能为空');
        if(empty($param['list_item'])) return $this->fail('list_item回答文本不能为空');
        if(empty($param['f_id'])) return $this->fail('f_id分类id不能为空');

        $param["admin_id"] = $this->adminId;
        $res = RecoveryFeedbackItem::addFeedbackItem($param);
        if($res > 0){
            return $this->success('success');
        }

        return $this->fail('fail');
    }


    /**
     * 常见问题管理列表 - 编辑
     * @param Request $request
     * @return void
     */
    public function updateFeedbackItem(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['content'])) return $this->fail('content问题标题不能为空');
        if(empty($param['list_item'])) return $this->fail('list_item回答文本不能为空');
        if(empty($param['f_id'])) return $this->fail('f_id分类id不能为空');

        $param["admin_id"] = $this->adminId;
        $res = RecoveryFeedbackItem::updateFeedbackItem($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：问题标题：{$param['content']}.";
        SystemOperationLog::addSystemLog($admin_id,'recovery','常见问题管理列表','updateFeedbackItem','编辑',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('编辑成功');
        }

        return $this->fail('编辑失败');
    }


    /**
     * 常见问题管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function deleteFeedbackItem(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = RecoveryFeedbackItem::where("id", $param['id'])->update(['delete_time'=>time()]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'recovery','常见问题管理列表','deleteFeedbackItem','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');

        return $this->fail('删除失败');
    }


    /**
     * 意见反馈管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getQuestionList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = RecoveryQuestion::getQuestionList($param);

        return $this->success($data);
    }


    /**
     * 意见反馈管理列表 - 查看
     * @param Request $request
     * @return mixed
     */
    public function getQuestionDetail(Request $request)
    {
        $param = $request->param();
        if(empty($param["id"])) return $this->fail('id不能为空');

        $detail = RecoveryQuestion::getQuestionDetail($param);

        return $this->success($detail ? $detail->toArray() : []);
    }


    /**
     * 意见反馈管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function deleteQuestionDetail(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = RecoveryQuestion::where("id", $param['id'])->update(['delete_time'=>date("Y-m-d H:i:s")]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'recovery','意见反馈管理列表','deleteQuestionDetail','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');

        return $this->fail('删除失败');
    }



    /**
     * 举报管理列表
     * @param Request $request
     * @return mixed
     */
    public function getReportList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = RecoveryReport::getReportList($param);

        return $this->success($data);
    }


    /**
     * 举报管理列表 - 查看
     * @param Request $request
     * @return mixed
     */
    public function getReportDetail(Request $request)
    {
        $param = $request->param();
        if(empty($param["id"])) return $this->fail('id不能为空');

        $detail = RecoveryReport::getReportDetail($param);

        return $this->success($detail ? $detail->toArray() : []);
    }


    /**
     * 属性库管理列表
     * @param Request $request
     * @return void
     * @throws \think\db\exception\DbException
     */
    public function getQuestionCateList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = RecoveryQuestionCate::getQuestionCateList($param);

        return $this->success($data);
    }


    /**
     * 属性库管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addQuestionCate(Request $request)
    {
        $param = $request->post();
        if(empty($param['type'])) return $this->fail('type类型id不能为空');
        if(empty($param['cate_name'])) return $this->fail('cate_name属性名称为空');

        $param["admin_id"] = $this->adminId;
        $res = RecoveryQuestionCate::addQuestionCate($param);
        if($res > 0){
            return $this->success('success');
        }
        return $this->fail('添加失败');
    }


    /**
     * 属性库管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function updateQuestionCate(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['type'])) return $this->fail('type类型id不能为空');
        if(empty($param['cate_name'])) return $this->fail('cate_name属性名称为空');

        $param["admin_id"] = $this->adminId;
        $res = RecoveryQuestionCate::updateQuestionCate($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：属性名称：{$param['cate_name']}.";
        SystemOperationLog::addSystemLog($admin_id,'recovery','属性库管理列表','updateQuestionCate','编辑',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('编辑成功');
        }
        return $this->fail('编辑失败');
    }



    /**
     * 类型管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function updateQuestionType(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['type'])) return $this->fail('type类型id不能为空');
        if(empty($param['type_name'])) return $this->fail('type_name类型名称为空');

        $param["admin_id"] = $this->adminId;
        $res = RecoveryQuestionType::updateQuestionType($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：类型名称：{$param['type_name']}.";
        SystemOperationLog::addSystemLog($admin_id,'recovery','类型管理列表','updateQuestionType','编辑',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('编辑成功');
        }
        return $this->fail('编辑失败');
    }



    /**
     * 类型管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function deleteQuestionType(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = RecoveryQuestionType::where("id", $param['id'])->update(['delete_time'=>time()]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'recovery','类型管理列表','deleteQuestionType','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');

        return $this->fail('删除失败');
    }


    /**
     * 属性库管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function deleteQuestionCate(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = RecoveryQuestionCate::where("id", $param['id'])->update(['delete_time'=>date("Y-m-d H:i:s")]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'recovery','属性库管理列表','deleteQuestionCate','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');

        return $this->fail('删除失败');
    }


    /**
     * 属性库管理列表 - 启用禁用
     * @param Request $request
     * @return mixed
     */
    public function enableQuestionCateStatus(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = RecoveryQuestionCate::enableQuestionCateStatus($param);

        return $this->success($msg);
    }


    /**
     * 类型管理列表 - 启用禁用
     * @param Request $request
     * @return mixed
     */
    public function enableQuestionTypeStatus(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = RecoveryQuestionType::enableQuestionTypeStatus($param);

        return $this->success($msg);
    }


    /**
     * 配置类型管理列表
     * @param Request $request
     * @return void
     */
    public function getQuestionTypeList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        $data = RecoveryQuestionType::getQuestionTypeList($param);

        return $this->success($data);
    }


    /**
     * 配置类型管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addQuestionType(Request $request)
    {
        $param = $request->param();
        if(empty($param['type'])) return $this->fail('type类型id不能为空');
        if(empty($param['type_name'])) return $this->fail('type_name属性名称为空');

        try {
            $param["admin_id"] = $this->adminId;
            $res = RecoveryQuestionType::addQuestionType($param);
            if ($res > 0) {
                return $this->success('success');
            }

            return $this->fail('添加失败');
        }catch (\Throwable $e){
            return $this->fail($e->getMessage());
        }
    }




    /**
     * 分类管理列表
     * @param Request $request
     * @return void
     * @throws \think\db\exception\DbException
     */
    public function getRecoveryCateList(Request $request)
    {
        $param = $request->post();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = RecoveryProductCategory::getRecoveryCateList($param);

        return $this->success($data);
    }


    /**
     * 分类管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addRecoveryCate(Request $request)
    {
        $param = $request->post();
        if(empty($param['cate_name'])) return $this->fail('cate_name属性名称为空');

        $res = RecoveryProductCategory::addRecoveryCate($param);
        if($res > 0){
            return $this->success('success');
        }
        return $this->fail('添加失败');
    }


    /**
     * 分类管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function updateRecoveryCate(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['cate_name'])) return $this->fail('cate_name属性名称为空');

        $param["admin_id"] = $this->adminId;
        $res = RecoveryProductCategory::updateRecoveryCate($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：分类名称：{$param['cate_name']}.";
        SystemOperationLog::addSystemLog($admin_id,'recovery','分类管理列表','updateRecoveryCate','编辑',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('编辑成功');
        }
        return $this->fail('编辑失败');
    }


    /**
     * 分类管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function deleteRecoveryCate(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = RecoveryProductCategory::where("id", $param['id'])->update(['delete_time'=>time()]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'recovery','分类管理列表','deleteRecoveryCate','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }


    /**
     * 分类管理列表 - 上下架
     * @param Request $request
     * @return mixed
     */
    public function enableRecoveryCate(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = RecoveryProductCategory::enableRecoveryCate($param);

        return $this->success($msg);
    }


    /**
     * 常见问题管理列表 - 上下架
     * @param Request $request
     * @return mixed
     */
    public function enableFeedbackItem(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = RecoveryFeedBackItem::enableFeedbackItem($param);

        return $this->success($msg);
    }


    /**
     * 意见反馈管理列表 - 启用禁用
     * @param Request $request
     * @return mixed
     */
    public function enableQuestionDetail(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = RecoveryQuestion::enableQuestionDetail($param);

        return $this->success($msg);
    }


    /**
     * 礼品卡后台 - 分类管理列表
     * @param Request $request
     * @return mixed
     */
    public function getRecruitIndustryList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = GiftCardCate::getGiftCardCateList($param);

        return $this->success($data);
    }


    /**
     * 回收/搬运入驻管理列表
     * @param Request $request
     * @return void
     */
    public function getRecoverySettleList(Request $request)
    {
        $param = $request->param();
        $param['limit'] = $param["limit"] ?? 10;
        $param['page'] = $param["page"] ?? 1;

        $data = RecoveryShop::getRecoverySettleList($param);

        return $this->success($data);
    }


    /**
     * 回收/搬运入驻管理列表 - 详情
     * @param Request $request
     * @return void
     */
    public function getRecoverySettleDetail(Request $request)
    {
        $param = $request->param();
        if(empty($param["id"])) return $this->fail('id不能为空');

        $detail = RecoveryShop::getRecoverySettleDetail($param);

        return $this->success($detail ? $detail->toArray() : []);
    }


    /**
     * 回收/搬运入驻管理列表 - 审核
     * @param Request $request
     * @return mixed
     */
    public function auditRecoverySettle(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['status'])) return $this->fail('status不能为空');
        $msg = "通过";
        if($param["status"] == 3){
            $msg = "不通过";
            if(empty($param['audit_desc'])) return $this->fail('audit_desc原因描述不能为空');
        }

        $res = RecoveryShop::auditRecoverySettle($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的回收/搬运入驻审核为{$msg}.";
        SystemOperationLog::addSystemLog($admin_id,'recovery','回收/搬运入驻管理列表','auditRecoverySettle','审核',$param,$ip,$desc);

        if($res >= 0){
            return $this->success('success');
        }
        return $this->fail('fail');
    }



    /**
     * 回收/搬运入驻管理列表 - 启用禁用状态更新
     * @param Request $request
     * @return mixed
     */
    public function enableRecoverySettle(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = RecoveryShop::enableRecoverySettle($param);

        return $this->success($msg);
    }


    /**
     * 活动管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getConfigActivityList (Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        $data = ConfigActivity::getConfigActivityList($param);

        return $this->success($data);
    }


    /**
     * 活动管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function deleteActivity(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = ConfigActivity::where("id", $param['id'])->update(['delete_time'=>date("Y-m-d H:i:s")]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'activity','活动管理列表','deleteActivity','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }


    /**
     * 活动管理列表 - 编辑
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function updateActivity(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['title'])) return $this->fail('title不能为空');
        if(empty($param['start_time'])) return $this->fail('start_time不能为空');
        if(empty($param['end_time'])) return $this->fail('end_time不能为空');
        if(empty($param['type'])) return $this->fail('type不能为空');
        if(empty($param['client_type'])) return $this->fail('client_type不能为空');
        if(empty($param['sort'])) return $this->fail('活动排序不能为空');
        if(empty($param['create_img'])) return $this->fail('活动封面不能为空');

        if(!empty($param["title"])){
            $find = ConfigActivity::where("title", $param["title"])->where("status",1)->where("id", "<>",$param["id"])->find();
            if(!empty($find)) return $this->fail('标题重复！');
        }
        if($param['type']==3){
            if (empty($param["goods_id"]))return $this->fail('商品不能为空');
        }
        $client_type_find = ConfigActivity::where("type", $param["type"])->where("status",1)
            ->where("client_type", $param["client_type"])
            ->where("id", "<>", $param["id"])
            ->find();
        if(!empty($client_type_find)) return $this->fail('配置类型数据重复！');

        if($param["type"] == 1){
            if(empty($param["integral"])) return $this->fail('integral积分数值不能为空！');
        }
        if($param["type"] == 2){
            if(empty($param["vip_day"])) return $this->fail('vip_day不能为空！');
        }

        $res = ConfigActivity::updateActivity($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：标题：{$param["title"]}.";
        SystemOperationLog::addSystemLog($admin_id,'activity','活动管理列表','updateActivity','编辑',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('编辑成功');
        return $this->fail('编辑失败');
    }

    public function get_goods_list(Request $request,StoreProductServices $services)
    {
        $where = $this->request->getMore([
            ['cate_id', ''],
            ['store_cate_id', ''],
            ['store_name', ''],
            ['type', 1, '', 'status'],
            ['is_live', 0],
            ['is_new', ''],
            ['is_vip_product', ''],
            ['is_presale_product', ''],
            ['data', '', '', 'time'],
            ['store_label_id', ''],
            ['brand_id', '']
        ]);
        $where['is_show'] = 1;
        $where['is_del'] = 0;
        $where['type'] = 1;

        unset($where['cate_id']);
        $list = $services->searchList($where);
        return $this->success($list);
    }
    /**
     * 添加活动
     * @param Request $request
     * @return mixed
     */
    public function addConfigActivity(Request $request)
    {
        $param = $request->param();
        if(empty($param['title'])) return $this->fail('title不能为空');
        if(empty($param['start_time'])) return $this->fail('start_time不能为空');
        if(empty($param['end_time'])) return $this->fail('end_time不能为空');
        if(empty($param['type'])) return $this->fail('type不能为空');
        if(empty($param['client_type'])) return $this->fail('client_type不能为空');
        if(empty($param['sort'])) return $this->fail('活动排序不能为空');
        if(empty($param['create_img'])) return $this->fail('活动封面不能为空');

        if(!empty($param["title"])){
            $find = ConfigActivity::where("title", $param["title"])->where("status",1)->find();
            if(!empty($find)) return $this->fail('标题重复！');
        }
        if($param['type']==3){
            if (empty($param["goods_id"]))return $this->fail('商品不能为空');
        }

        $client_type_find = ConfigActivity::where("type", $param["type"])->where("status",1)->where("client_type", $param["client_type"])->find();
        if(!empty($client_type_find)) return $this->fail('配置类型数据重复！');

        if($param["type"] == 1){
            if(empty($param["integral"])) return $this->fail('integral积分数值不能为空！');
        }
        if($param["type"] == 2){
            if(empty($param["vip_day"])) return $this->fail('vip_day不能为空！');
        }

        $param["admin_id"] = $this->adminId;
        $res = ConfigActivity::addConfigActivity($param);
        if($res > 0){
            return $this->success('success');
        }
        return $this->fail('添加失败');
    }



    /**
     * 活动管理列表 - 启用禁用状态更新
     * @param Request $request
     * @return mixed
     */
    public function enableActivityStatus(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = ConfigActivity::enableBannerStatus($param);

        return $this->success($msg);
    }


    /**
     * 活动管理列表 - 获取客户端类型列表
     * @param Request $request
     * @return mixed
     */
    public function getActivityClientTypeList(Request $request)
    {
        $param = $request->param();

        $data = ConfigActivity::getActivityClientTypeList($param);

        return $this->success($data);
    }




    /**
     * 文案配置管理列表
     * @return mixed
     */
    public function getRecoveryInstructionList(Request $request)
    {
        $param = $request->param();
        $param['page'] = input('param.page', 1);
        $param['limit'] = input('param.limit', 10);

        $data = RecoveryInstruction::getRecoveryInstructionList($param);
        return $this->success($data);
    }


    /**
     * 文案配置管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addRecoveryInstruction(Request $request)
    {
        $param = $request->post();
        if(empty($param['desc'])) return $this->fail('desc不能为空');
        if(empty($param['type'])) return $this->fail('type不能为空');

        $res = RecoveryInstruction::addRecoveryInstruction($param);
        if($res > 0){
            return $this->success('success');
        }
        return $this->fail('添加失败');
    }


    /**
     * 文案配置管理列表 - 编辑
     * @param Request $request
     * @return mixed
     */
    public function updateRecoveryInstruction(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['desc'])) return $this->fail('desc不能为空');
        if(empty($param['type'])) return $this->fail('type不能为空');

        $res = RecoveryInstruction::updateRecoveryInstruction($param);
        if($res >= 0){
            return $this->success('编辑成功');
        }

        return $this->fail('编辑失败');
    }


    /**
     * 文案配置管理列表 - 删除
     * @return void
     */
    public function deleteRecoveryInstruction(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = RecoveryInstruction::where("id", $param['id'])->update(['delete_time'=>time()]);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }


    /**
     * 文案配置管理列表 - 启用禁用
     * @return void
     */
    public function enableRecoveryInstruction(Request $request)
    {
        $param = $request->post();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = RecoveryInstruction::enableRecoveryInstruction($param);

        return $this->success($msg);
    }


    /**
     * 文案配置管理列表 - 获取类型列表数据
     * @param Request $request
     * @return void
     */
    public function getRecoveryInstructionData(Request $request)
    {
        $data = RecoveryInstruction::getRecoveryInstructionData();
        return $this->success($data);
    }



    /**
     * 个人中心服务管理列表
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function getConfigServList (Request $request)
    {
        $param = $request->param();
        $param['limit'] = input('param.limit', 10);
        $param['page'] = input('param.page', 1);

        $data = ConfigServ::getConfigServList($param);

        return $this->success($data);
    }


    /**
     * 个人中心服务管理列表 - 删除
     * @param Request $request
     * @return mixed
     */
    public function deleteServ(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $res = ConfigServ::where("id", $param['id'])->update(['delete_time'=>time()]);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据删除.";
        SystemOperationLog::addSystemLog($admin_id,'config','个人中心服务管理列表','deleteServ','删除',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('删除成功');
        return $this->fail('删除失败');
    }


    /**
     * 个人中心服务管理列表 - 编辑
     * @param Request $request
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function updateServ(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');
        if(empty($param['title'])) return $this->fail('title不能为空');
        if(empty($param['img'])) return $this->fail('img不能为空');
        if(!empty($param["link_type"])){
            if(empty($param['link_content'])) return $this->fail('link_content链接url不能为空');
        }
        if(!empty($param["title"])){
            $find = ConfigServ::where("title", $param["title"])->where("status",1)->where("id", "<>",$param["id"])->find();
            if(!empty($find)) return $this->fail('标题重复！');
        }

        $res = ConfigServ::updateServ($param);

        $admin_id = $this->adminId;
        $ip = $request->ip();
        $desc = "-将id为{$param['id']}的数据编辑为：标题：{$param["title"]}.";
        SystemOperationLog::addSystemLog($admin_id,'config','个人中心服务管理列表','updateServ','编辑',$param,$ip,$desc);

        if ($res >= 0)  return $this->success('编辑成功');
        return $this->fail('编辑失败');
    }


    /**
     * 个人中心服务管理列表 - 添加
     * @param Request $request
     * @return mixed
     */
    public function addConfigServ(Request $request)
    {
        $param = $request->param();
        if(empty($param['title'])) return $this->fail('title不能为空');
        if(empty($param['img'])) return $this->fail('img不能为空');
        if(!empty($param["link_type"])){   //link_type为1、2、3的情况下， link_content为必填字段
            if(empty($param['link_content'])) return $this->fail('link_content链接url不能为空');
        }

        $param["admin_id"] = $this->adminId;
        $res = ConfigServ::addConfigServ($param);
        if($res > 0){
            return $this->success('success');
        }
        return $this->fail('添加失败');
    }



    /**
     * 个人中心服务管理列表 - 启用禁用状态更新
     * @param Request $request
     * @return mixed
     */
    public function enableServStatus(Request $request)
    {
        $param = $request->param();
        if(empty($param['id'])) return $this->fail('id不能为空');

        $msg = ConfigServ::enableServStatus($param);

        return $this->success($msg);
    }




}